﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Progresoft.Scheduler.RemoteInterface.Api;

public partial class ViewLog : System.Web.UI.Page
{
	/// <summary>
	/// Ид задачи
	/// </summary>
	protected int? LogID
	{
		get
		{
			return this.Request.QueryString["log"] == null ?
				null : (int?)Convert.ToInt32(this.Request.QueryString["log"]);
		}
	}

	/// <summary>
	/// Система
	/// </summary>
	protected string System
	{
		get
		{
			return this.Request.QueryString["system"] == null ?
				string.Empty : this.Request.QueryString["system"].ToString();
		}
	}

	/// <summary>
	/// Тип задачи
	/// </summary>
	protected string Type
	{
		get
		{
			return this.Request.QueryString["type"] == null ?
				null : this.Request.QueryString["type"].ToString();
		}
	}

	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			if (this.System == string.Empty)
				throw new Exception("Не задан обязательный параметр system");
			
			if (!this.LogID.HasValue)
				throw new Exception("не задан обазательный параметр log");

			if (string.IsNullOrEmpty(this.Type))
				throw new Exception("не задан обязательный параметр type");

			string serverUrl = ConnectorManager.GetServerUrl(this.System);
			Connector connector = ConnectorManager.GetConnector();
			SchedulerServer server = connector.GetServer(serverUrl);

			string log, title;
			log = server.GetTaskLog(this.LogID.Value, this.Type, out title);
			this.litTitle.Text = title;
			this.litLog.Text = string.IsNullOrEmpty(log) ? string.Empty : log.Replace("\r\n", "<br />");
			if (Request.UrlReferrer != null)
				hlBack.NavigateUrl = Request.UrlReferrer.PathAndQuery;
		}
	}
}
